package cn.hj.springboot_mybatis.mapper;

import cn.hj.springboot_mybatis.pojo.Person;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PersonMapper {
    @Select("select * from t_person where p_id=#{id}")
    @Results(id = "person", value = {@Result(column = "name", property = "p_name"), @Result(column = "age", property = "p_age")})
    Person findOnePerson(Integer id);

    @Select("select * from t_person")
    @ResultMap("person")
    List<Person> getAllPerson();

    @Options(useGeneratedKeys = true,keyProperty = "p_id")
    @Insert("insert into t_person(name,age) values(#{p_name},#{p_age})")
    int insertPerson(Person p);
    @Delete("delete from t_person where p_id=#{id}")
    int deletePerson(Integer id);
    @Update("update t_person set name=#{p_name},age=#{p_age} where p_id=#{p_id}")
    int updatePerson(Person p);
}
